package com.briup.execrise.service;

import com.briup.execrise.mapper.StudentMapper;
import com.briup.execrise.pojo.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.Date;
import java.util.List;

@Service
public class StudentService {

    @Autowired
    private StudentMapper studentMapper;
    public Student select(int id){
        Student student=studentMapper.selectByPrimaryKey(id);
        return student;
    }
    //查询所有数据
    public List<Student>selectAll(){
        List<Student> list =studentMapper.selectAll();
        return list;
    }
    //插入数据
    public void insertData(int id, int age, double salary, String name, Date birthday){
        Student student=new Student();
        student.setBirthday(new Date());
        student.setId(id);
        student.setAge(age);
        student.setName(name);
        studentMapper.insert(student);
        System.out.println("插入成功");
    }
    //删除数据
    public void delete(String name){
        Example example=new Example(Student.class);
        example.createCriteria().andLike("name","%三%");
        studentMapper.deleteByExample(example);
    }
}
